import java.util.Optional;

/**
 * @author ypz
 * @date 2021/9/10 10:52
 */
public class OptionalTest {
    public static void main(String[] args) {
        Optional<String> optional = Optional.ofNullable(null);
        //Optional实例为null,则isPresent返回false,
        System.out.println(optional.isPresent()); //false

        Optional<String> zhangsan = Optional.ofNullable("zhangsan");
        System.out.println(zhangsan.isPresent()); //true

        //如果Optional接收的实例为null，则可以接收一个lambda表达式生成一个新的值
        System.out.println(optional.orElseGet(()->"[null]"));
    }

    public Integer hello(){
        Optional<Integer> optional = Optional.ofNullable(null);
        //
        optional.orElseGet(()->123);
        return 0;
    }
}
